package com.zhida84.Servlet;
/**
 * 
 * @author shazhengbo sunchangxing
 *
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.zhida84.Dao.RecruitDao;
import com.zhida84.Entity.RecruitTab;
import com.zhida84.Impl.RecruitImpl;

/**
 * Servlet implementation class searchRecruitServlet
 */
public class searchRecruitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public searchRecruitServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		request.setCharacterEncoding("UTF-8");
		try {
			PrintWriter out = response.getWriter();
			String stringKey = request.getParameter("stringKey");
			String array[] = stringKey.split(",");
			String keyWorld = array[1];
			String keyType = array[0];
			String numkey = array[2];
			String strQuery = null;
			int num = Integer.parseInt(numkey);
			if (keyType.equals("alltype")) {
				strQuery = "select * from recruittable  order by  issueDate DESC limit "
						+ num + ",10";
			}
			else if (keyType.equals("payment")) {
				strQuery = "select * from  recruittable where  reType = '" + keyWorld + "'  order by  issueDate DESC limit "
						+ num + ",10";
			} else {
				strQuery = "select * from  recruittable where  reType = '" + keyWorld + "' order by  payment DESC limit "
						+ num + ",10";
			}
			
			System.out.println(strQuery);
			RecruitDao recDao = new RecruitImpl();
			ResultSet rs = recDao.searchRescruit(strQuery);
			ArrayList<RecruitTab> list = new ArrayList<RecruitTab>();
			while (rs.next()) {
				RecruitTab recruit = new RecruitTab();
				recruit.setRecruitId(rs.getInt("recruitId"));
				recruit.setReSex(rs.getString("reSex"));
				recruit.setReSalary(rs.getFloat("reSalary"));
				recruit.setActType(rs.getString("actType"));
				recruit.setJobName(rs.getString("jobName"));
				recruit.setReType(rs.getString("reType"));
				recruit.setSalaryType(rs.getString("salaryType"));
				String issueDate=rs.getString("issueDate").substring(0, 10);
				recruit.setIssueDate(issueDate);
				list.add(recruit);
			}
			JSONArray ja = JSONArray.fromObject(list);
			out.print(ja); // �������
			out.close();
		} catch (Exception e) {
		}
	}
}
